home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / tracker-4.13.lha / tracker / display.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-15  |  10.7 KB  |  508 lines

  1. /* display.c 
  2.     vi:ts=3 sw=3:
  3.  */
  4.  
  5. /* $Id: display.c,v 4.9 1995/02/14 04:02:28 espie Exp $
  6.  * $Log: display.c,v $
  7.  * Revision 4.9  1995/02/14  04:02:28  espie
  8.  * Kludge for the amiga.
  9.  *
  10.  * Revision 4.9  1995/02/14  04:02:28  espie
  11.  * Kludge for the amiga.
  12.  *
  13.  * Revision 4.8  1995/02/08  13:14:56  espie
  14.  * *** empty log message ***
  15.  *
  16.  * Revision 4.7  1995/02/06  14:50:47  espie
  17.  * Changed sample_info.
  18.  *
  19.  * Revision 4.6  1995/02/01  20:41:45  espie
  20.  * Added color.
  21.  *
  22.  * Revision 4.5  1995/02/01  16:39:04  espie
  23.  * Includes moved to defs.h
  24.  *
  25.  * Revision 4.5  1995/02/01  16:39:04  espie
  26.  * Includes moved to defs.h
  27.  *
  28.  * Revision 4.0  1994/01/11  17:45:22  espie
  29.  * Major change: does not use sprintf heavily.
  30.  *
  31.  * Generalized open.c.
  32.  * Use name_of_note(), no need for run_in_fg().
  33.  * Small bug: strcpy -> stringcopy.
  34.  * Cond code to make show/not show robust.
  35.  * Added instrument name as shown per display.c.
  36.  * Major change: use scroller interface.
  37.  * Lots of LOCAL added + minor changes.
  38.  * Try to get rid of %d format in printf.
  39.  */
  40.      
  41. #include "defs.h"
  42. #include "song.h"
  43. #include "channel.h"
  44. #include "extern.h"
  45. #include "tags.h"
  46. #include "prefs.h"
  47.  
  48. ID("$Id: display.c,v 4.9 1995/02/14 04:02:28 espie Exp $")
  49. LOCAL void init_display P((void));
  50. LOCAL void (*INIT)P((void)) = init_display;
  51.      
  52. #define ENTRY_SIZE 14
  53. LOCAL char *base;
  54.  
  55. LOCAL char *num[] = {
  56. " 0", " 1", " 2", " 3", " 4", " 5", " 6", " 7", " 8", " 9",
  57. "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
  58. "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
  59. "30", "31", "32", "33", "34", "35", "36", "37", "38", "39",
  60. "40", "41", "42", "43", "44", "45", "46", "47", "48", "49",
  61. "50", "51", "52", "53", "54", "55", "56", "57", "58", "59",
  62. "60", "61", "62", "63", "64", "65", "66", "67", "68", "69",
  63. "70", "71", "72", "73", "74", "75", "76", "77", "78", "79",
  64. "80", "81", "82", "83", "84", "85", "86", "87", "88", "89",
  65. "90", "91", "92", "93", "94", "95", "96", "97", "98", "99",
  66. "00", "01", "02", "03", "04", "05", "06", "07", "08", "09"};
  67.  
  68. char instname[] = { ' ', '1', '2', '3', '4', '5', '6', '7', '9',
  69. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  70. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
  71.  
  72. LOCAL void reset_buffer()
  73.    {
  74.    base = new_scroll();
  75.    }
  76.  
  77. LOCAL void next_entry()
  78.    {
  79.     if (get_pref_scalar(PREF_COLOR))
  80.         base += 7;
  81.    base += ENTRY_SIZE;
  82.    }
  83.  
  84. LOCAL void copy1(to, from)
  85. char *to, *from;
  86.    {
  87.    *to = *from;
  88.    }
  89.    
  90. LOCAL void copy2(to, from)
  91. char *to, *from;
  92.    {
  93.    *to++ = *from++;
  94.    *to = *from;
  95.    }
  96.  
  97. LOCAL void copy3(to, from)
  98. char *to, *from;
  99.    {
  100.    *to++ = *from++;
  101.    *to++ = *from++;
  102.    *to = *from;
  103.    }
  104.  
  105. LOCAL void stringcopy(to, from)
  106. char *to, *from;
  107.    {
  108.    while (*from)
  109.       *to++ = *from++;
  110.    }
  111.  
  112. LOCAL void num2(to, n)
  113. char *to;
  114. int n;
  115.    {
  116.    char *v = num[n];
  117.    *to++ = *v++;
  118.    *to = *v;
  119.    }
  120.  
  121. LOCAL void num3(to, n)
  122. char *to;
  123. int n;
  124.    {
  125.    char *v;
  126.  
  127.    if (n >= 100)
  128.       *to = "0123456789"[n/100];
  129.    while (n > 109)
  130.       n -= 100;
  131.    v = num[n];
  132.    to++;
  133.    *to++ = *v++;
  134.    *to = *v;
  135.    }
  136.  
  137. LOCAL void (*table[NUMBER_EFFECTS]) P((int samp, int para, int note, struct channel *ch));
  138.  
  139. LOCAL void disp_default(samp, para, note, ch)
  140. int samp, para, note;
  141. struct channel *ch;
  142.    {
  143.    copy3(base+2, name_of_note(note));
  144.    }
  145.  
  146. LOCAL void disp_speed(samp, para, note, ch)
  147. int samp, para, note;
  148. struct channel *ch;
  149.    {
  150.    copy3(base+2, name_of_note(note));
  151.    if (para < 32)
  152.       {
  153.       stringcopy(base+6, "SPD");
  154.       num2(base+10, para);
  155.       }
  156.    else
  157.       {
  158.       stringcopy(base+6, "spd%");
  159.       num3(base+10, para * 100/NORMAL_FINESPEED);
  160.       }
  161.    }
  162.  
  163. LOCAL void disp_nothing(samp, para, note, ch)
  164. int samp, para, note;
  165. struct channel *ch;
  166.    {
  167.    }
  168.  
  169. LOCAL void disp_portamento(samp, para, note, ch)
  170. int samp, para, note;
  171. struct channel *ch;
  172.    {
  173.    stringcopy(base+2, "-->");
  174.    copy3(base+5, name_of_note(note));
  175.    if (para)
  176.       {
  177.       base[8] = '(';
  178.       num3(base+9, para);
  179.       base[12] = ')';
  180.       }
  181.    }
  182.  
  183. LOCAL void disp_portaslide(samp, para, note, ch)
  184. int samp, para, note;
  185. struct channel *ch;
  186.    {
  187.    stringcopy(base+2, "-->");
  188.    copy3(base+5, name_of_note(note));
  189.    if (LOW(para))
  190.       {
  191.       base[9] = '-';
  192.       num2(base+10, LOW(para));
  193.       }
  194.    else
  195.       {
  196.       base[9] = '+';
  197.       num2(base+10, HI(para));
  198.       }
  199.    }
  200.  
  201. LOCAL void disp_upslide(samp, para, note, ch)
  202. int samp, para, note;
  203. struct channel *ch;
  204.    {
  205.    copy3(base+2, name_of_note(note));
  206.    base[8] = '-';
  207.    if (para)
  208.       num3(base+9, para);
  209.    }
  210.  
  211. LOCAL void disp_downslide(samp, para, note, ch)
  212. int samp, para, note;
  213. struct channel *ch;
  214.    {
  215.    copy3(base+2, name_of_note(note));
  216.    base[8] = '+';
  217.    if (para)
  218.       num3(base+9, para);
  219.    }
  220.  
  221. LOCAL void disp_vibrato(samp, para, note, ch)
  222. int samp, para, note;
  223. struct channel *ch;
  224.    {
  225.    copy3(base+2, name_of_note(note));
  226.    copy2(base+6, "vb");
  227.    if (para)
  228.       {
  229.       num2(base+8, LOW(para));
  230.       base[10] = '/';
  231.       num2(base+11, HI(para));
  232.       }
  233.    }
  234.  
  235. LOCAL void disp_vibratoslide(samp, para, note, ch)
  236. int samp, para, note;
  237. struct channel *ch;
  238.    {
  239.    copy3(base+2, name_of_note(note));
  240.    stringcopy(base+6, "vibs");
  241.    if (LOW(para))
  242.       {
  243.       base[10] = '-';
  244.       num2(base+11, LOW(para));
  245.       }
  246.    else
  247.       {
  248.       base[10] = '+';
  249.       num2(base+11, HI(para));
  250.       }
  251.    }
  252.  
  253. LOCAL void disp_slidevol(samp, para, note, ch)
  254. int samp, para, note;
  255. struct channel *ch;
  256.    {
  257.    copy3(base+2, name_of_note(note));
  258.    stringcopy(base+6, "vol");
  259.    if (LOW(para))
  260.       {
  261.       base[10] = '-';
  262.       num2(base+11, LOW(para));
  263.       }
  264.    else
  265.       if (HI(para))
  266.          {
  267.          base[10] = '+';
  268.          num2(base+11, HI(para));
  269.          }
  270.    }
  271.  
  272. LOCAL void disp_volume(samp, para, note, ch)
  273. int samp, para, note;
  274. struct channel *ch;
  275.    {
  276.    copy3(base+2, name_of_note(note));
  277.    if (para)
  278.       {
  279.       stringcopy(base+6, "vol");
  280.       num3(base+10, para);
  281.       }
  282.    else
  283.       stringcopy(base+6, "silent");
  284.    }
  285.  
  286. LOCAL void disp_arpeggio(samp, para, note, ch)
  287. int samp, para, note;
  288. struct channel *ch;
  289.    {
  290.    if (note != NO_NOTE)
  291.       {
  292.       copy3(base+2, name_of_note(note));
  293.       copy3(base+6, name_of_note(note + LOW(para)));
  294.       copy3(base+10, name_of_note(note + HI(para)));
  295.       }
  296.    else
  297.       if (ch->note == NO_NOTE)
  298.          stringcopy(base, "Arp error");
  299.       else
  300.          {
  301.          copy3(base+6, name_of_note(ch->note + LOW(para)));
  302.          copy3(base+10, name_of_note(ch->note + HI(para)));
  303.          }  
  304.    }
  305.  
  306. LOCAL void disp_retrig(samp, para, note, ch)
  307. int samp, para, note;
  308. struct channel *ch;
  309.    {
  310.    copy3(base+2, name_of_note(note));
  311.    stringcopy(base + 6, "rtg");
  312.    num3(base+9, para);
  313.    }
  314.  
  315. LOCAL void disp_note_cut(samp, para, note, ch)
  316. int samp, para, note;
  317. struct channel *ch;
  318.    {
  319.    copy3(base+2, name_of_note(note));
  320.    stringcopy(base+6, "cut");
  321.    num3(base+9, para);
  322.    }
  323.  
  324. LOCAL void disp_late_start(samp, para, note, ch)
  325. int samp, para, note;
  326. struct channel *ch;
  327.    {
  328.    copy3(base+2, name_of_note(note));
  329.    stringcopy(base+6, "lte");
  330.    num3(base+9, para);
  331.    }
  332.  
  333. LOCAL void disp_offset(samp, para, note, ch)
  334. int samp, para, note;
  335. struct channel *ch;
  336.    {
  337.    copy3(base+2, name_of_note(note));
  338.    stringcopy(base+6, "off   %");
  339.    num3(base+9, para * 25600/ch->samp->length);
  340.    }
  341.  
  342. LOCAL void disp_smooth_up(samp, para, note, ch)
  343. int samp, para, note;
  344. struct channel *ch;
  345.    {
  346.    copy3(base+2, name_of_note(note));
  347.    stringcopy(base+6, "sth-");
  348.    num3(base+10, para);
  349.    }
  350.  
  351. LOCAL void disp_smooth_down(samp, para, note, ch)
  352. int samp, para, note;
  353. struct channel *ch;
  354.    {
  355.    copy3(base+2, name_of_note(note));
  356.    stringcopy(base+6, "sth+");
  357.    num3(base+10, para);
  358.    }
  359.  
  360. LOCAL void disp_smooth_upvolume(samp, para, note, ch)
  361. int samp, para, note;
  362. struct channel *ch;
  363.    {
  364.    copy3(base+2, name_of_note(note));
  365.    stringcopy(base+8, "++");
  366.    num3(base+10, para);
  367.    }
  368.  
  369. LOCAL void disp_smooth_downvolume(samp, para, note, ch)
  370. int samp, para, note;
  371. struct channel *ch;
  372.    {
  373.    copy3(base+2, name_of_note(note));
  374.    stringcopy(base+8, "--");
  375.    num3(base+10, para);
  376.    }
  377.  
  378. LOCAL void disp_change_finetune(samp, para, note, ch)
  379. int samp, para, note;
  380. struct channel *ch;
  381.    {
  382.    copy3(base+2, name_of_note(note));
  383.    stringcopy(base+6, "fine");
  384.    num2(base+11, para);
  385.    }
  386.  
  387. LOCAL void disp_skip(samp, para, note, ch)
  388. int samp, para, note;
  389. struct channel *ch;
  390.    {
  391.    copy3(base+2, name_of_note(note));
  392.    if (para)
  393.       {
  394.       stringcopy(base+6, "skp");
  395.       num3(base+10, para);
  396.       }
  397.    else
  398.       stringcopy(base+6, "next");
  399.    }
  400.  
  401. LOCAL void disp_fastskip(samp, para, note, ch)
  402. int samp, para, note;
  403. struct channel *ch;
  404.    {
  405.    copy3(base+2, name_of_note(note));
  406.    stringcopy(base+6, "ff");
  407.    num3(base+10, para);
  408.    }
  409.  
  410. LOCAL void disp_loop(samp, para, note, ch)
  411. int samp, para, note;
  412. struct channel *ch;
  413.    {
  414.    copy3(base+2, name_of_note(note));
  415.    if (para == 0)
  416.       stringcopy(base+6, "SETLOOP");
  417.    else
  418.       {
  419.       stringcopy(base+6, "LOOP");
  420.       num3(base+10, para);
  421.       }
  422.    }
  423.  
  424. LOCAL void disp_delay_pattern(samp, para, note, ch)
  425. int samp, para, note;
  426. struct channel *ch;
  427.    {
  428.    copy3(base+2, name_of_note(note));
  429.    stringcopy(base+6, "DLAY");
  430.    num3(base+10, para);
  431.    }
  432.  
  433. #define disp_nothing disp_default
  434.  
  435. LOCAL void init_display()
  436.    {
  437.    int i;
  438.  
  439.    for (i = 0; i < NUMBER_EFFECTS; i++)
  440.       table[i] = disp_nothing;
  441.    table[EFF_ARPEGGIO] = disp_arpeggio;
  442.    table[EFF_SPEED] = disp_speed;
  443.    table[EFF_SKIP] = disp_skip;
  444.    table[EFF_FF] = disp_fastskip;
  445.    table[EFF_VOLUME] = disp_volume;
  446.    table[EFF_VOLSLIDE] = disp_slidevol;
  447.    table[EFF_OFFSET] = disp_offset;
  448.    table[EFF_PORTA] = disp_portamento;
  449.    table[EFF_PORTASLIDE] = disp_portaslide;
  450.    table[EFF_UP] = disp_upslide;
  451.    table[EFF_DOWN] = disp_downslide;
  452.    table[EFF_VIBRATO] = disp_vibrato;
  453.    table[EFF_VIBSLIDE] = disp_vibratoslide;
  454.    table[EFF_SMOOTH_UP] = disp_smooth_up;
  455.    table[EFF_SMOOTH_DOWN] = disp_smooth_down;
  456.    table[EFF_CHG_FTUNE] = disp_change_finetune;
  457.    table[EFF_LOOP] = disp_loop;
  458.    table[EFF_RETRIG] = disp_retrig;
  459.    table[EFF_S_UPVOL] = disp_smooth_upvolume;
  460.    table[EFF_S_DOWNVOL] = disp_smooth_downvolume;
  461.    table[EFF_NOTECUT] = disp_note_cut;
  462.    table[EFF_LATESTART] = disp_late_start;
  463.    table[EFF_DELAY] = disp_delay_pattern;
  464.    reset_buffer();
  465.    }
  466.  
  467. void dump_event(ch, e)
  468. struct channel *ch;
  469. struct event *e;
  470.    {
  471.    INIT_ONCE;
  472.    
  473.     if (ch && base)
  474.         {
  475.         if (get_pref_scalar(PREF_COLOR))
  476.             {
  477.             *base++ ='\033';
  478.             *base++ ='[';
  479.             *base++ ='0';
  480.             *base++ =';';
  481.             *base++ ='3';
  482.             if (ch->samp)
  483.                 *base++ ='0'+ch->samp->color; /* instname[e->sample_number]%8;*/
  484.             else
  485.                 *base++ = '0';
  486.             *base++ ='m';
  487.             }
  488.         *base = instname[e->sample_number];
  489.         (*table[e->effect])(e->sample_number, e->parameters, e->note, ch);
  490.         next_entry();
  491.         }
  492.     else
  493.         {
  494.         scroll();
  495.         reset_buffer();
  496.         }
  497.     }
  498.  
  499. void dump_delimiter()
  500.     {
  501.     INIT_ONCE;
  502. #ifdef AMIGA
  503.    *base++;
  504. #else
  505.     *base++= '|';
  506. #endif
  507.     }
  508.